home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / schematk / src_1152.lha / Graphics.subproj / GraphicsView.m < prev    next >
Encoding:
Text File  |  1992-07-10  |  7.3 KB  |  209 lines

  1. /* Copyright รก 1991 Gustavus Adolphus College.  All rights reserved.
  2.  *
  3.  * Schematik was developed by Gustavus Adolphus College (GAC) with
  4.  * support from NeXT Computer, Inc.  Permission to copy this software,
  5.  * to redistribute it, and to use it for any purpose is granted,
  6.  * subject to the following restrictions and understandings.
  7.  *
  8.  * 1. Any copy made of this software must include this copyright
  9.  * notice in full.
  10.  *
  11.  * 2. Users of this software agree to make their best efforts (a) to
  12.  * return to the GAC Mathematics and Computer Science Department any
  13.  * improvements or extensions that they make, so that these may be
  14.  * included in future releases; and (b) to inform GAC of noteworthy
  15.  * uses of this software.
  16.  *
  17.  * 3. All materials developed as a consequence of the use of this
  18.  * software shall duly acknowledge such use, in accordance with the
  19.  * usual standards of acknowledging credit in academic research.
  20.  *
  21.  * 4. GAC makes no express or implied warranty or representation of
  22.  * any kind with respect to this software, including any warranty
  23.  * that the operation of this software will be error-free.  ANY
  24.  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
  25.  * PURPOSE IS HEREBY DISCLAIMED.  GAC is under no obligation to
  26.  * provide any services, by way of maintenance, update, or otherwise.
  27.  *
  28.  * 5. In conjunction with products arising from the use of this
  29.  * material, there shall be no use of the name of Gustavus Adolphus
  30.  * College nor of any adaptation thereof in any advertising,
  31.  * promotional, or sales literature without prior written consent
  32.  * from GAC in each case.
  33.  */
  34.  
  35. #import "GraphicsView.h"
  36. #import "../defines.h"
  37. #import Main_h
  38. #import SchemeProtocol_h
  39. #import PrefAgent_h
  40. #import <appkit/NXCachedImageRep.h>
  41. #import <appkit/NXImage.h>
  42. #import <appkit/ScrollView.h>
  43. #import <appkit/Window.h>
  44. #import <appkit/nextstd.h>
  45. #import <appkit/publicWraps.h>
  46. #import <dpsclient/wraps.h>
  47. #import <objc/Storage.h>
  48. #import <defaults.h>
  49. #import <mach.h>
  50. #import <string.h>
  51.  
  52. static void flushTEHandler(DPSTimedEntry, double, id);
  53.  
  54. #define GRAPHICSZONENAME    "Graphics"
  55. #define MINIWINDOWICON        "GraphicsWin.tiff"
  56. #define TEMPSTRINGLENGTH    1040
  57. #define WINDOWOFFSET        20
  58. #define WINDOWTOPBOUND        830
  59. #define WINDOWROLLBOUND        800
  60. #define WINDOWRIGHTBOUND    1050
  61. #define AUTOFLUSHMODE        1
  62. #define NONFLUSHMODE        0
  63. #define MINDOCVIEWSIZE        {120.0,60.0}
  64.  
  65. static unsigned windowNumber=0;
  66. static NXSize minWindowSize;
  67.  
  68. @implementation GraphicsView
  69.  
  70. + initialize
  71. {
  72.     NXSize minDocSize=MINDOCVIEWSIZE,size1;
  73.     NXRect tempFrame,tempRect;
  74.     [ScrollView getFrameSize:&size1 forContentSize:&minDocSize horizScroller:YES vertScroller:YES borderType:NX_NOBORDER];
  75.     NXSetRect(&tempRect,0.0,0.0,size1.width,size1.height);
  76.     [Window getFrameRect:&tempFrame forContentRect:&tempRect style:NX_RESIZEBARSTYLE];
  77.     minWindowSize.width=tempFrame.size.width;
  78.     minWindowSize.height=tempFrame.size.height;
  79.     return self;
  80. }
  81.  
  82. - initFrame:(NXRect *)frameRect window:(unsigned)winNum
  83. {
  84.     NXSize size1,size2,size3,size4=MINDOCVIEWSIZE,size5;
  85.     NXRect contentRect;
  86.     id theWindow,scrollView;
  87.     char buffer[TEMPSTRINGLENGTH];
  88.     unsigned int globalWinNum;
  89.  
  90. DEBUG_FUNC1(DEBUGLEVEL);
  91.  
  92.     [super initFrame:frameRect];
  93.     number = winNum;
  94.     windowNum = windowNumber++;
  95.     flushMode = NONFLUSHMODE;
  96.     flushTE = (DPSTimedEntry)0;
  97.     cache = [[Window allocFromZone:[self zone]] initContent:&bounds style:NX_PLAINSTYLE backing:NX_RETAINED buttonMask:0 defer:NO];
  98.     imageRep = [[NXCachedImageRep allocFromZone:[self zone]] initFromWindow:cache rect:&bounds];
  99.     theImage = [[NXImage allocFromZone:[self zone]] initSize:&(bounds.size)];
  100.     [theImage setUnique:YES];
  101.     [theImage useRepresentation:imageRep];
  102.     [theImage setScalable:YES];
  103.     [ScrollView getFrameSize:&size3 forContentSize:&(bounds.size) horizScroller:YES vertScroller:YES borderType:NX_NOBORDER];
  104.     NXSetRect(&contentRect,0.0,0.0,size3.width,size3.height);
  105.     [Window getFrameRect:frameRect forContentRect:&contentRect style:NX_RESIZEBARSTYLE];
  106.     maxWindowSize.width = frameRect->size.width;
  107.     maxWindowSize.height = frameRect->size.height;
  108.     NXConvertWinNumToGlobal([cache windowNum], &globalWinNum);
  109.     [[NXApp protocolObj] sendGraphicsWindow:globalWinNum];
  110.  
  111.     [[NXApp prefAgent] getGraphicsSize:&size1];
  112.     [[NXApp prefAgent] getGraphicsTolerance:&size2];
  113.     size1.width = (((size1.width+size2.width)<bounds.size.width)?size1.width:bounds.size.width);
  114.     size1.height = (((size1.height+size2.height)<bounds.size.height)?size1.height:bounds.size.height);
  115.  
  116.     [ScrollView getFrameSize:&size3 forContentSize:&size1 horizScroller:YES vertScroller:YES borderType:NX_NOBORDER];
  117.     [ScrollView getFrameSize:&size5 forContentSize:&size4 horizScroller:YES vertScroller:YES borderType:NX_NOBORDER];
  118.     size3.width = MAX(size3.width, size5.width);
  119.     size3.height = MAX(size3.height, size5.height);
  120.     NXSetRect(frameRect,0.0,0.0,size3.width,size3.height);
  121.     scrollView = [[ScrollView allocFromZone:[self zone]] initFrame:frameRect];
  122.     [scrollView setBorderType:NX_NOBORDER];
  123.     [scrollView setHorizScrollerRequired:YES];
  124.     [scrollView setVertScrollerRequired:YES];
  125.     [scrollView setDocView:self];
  126.  
  127.     theWindow = [[Panel allocFromZone:[self zone]] initContent:frameRect style:NX_RESIZEBARSTYLE backing:NX_BUFFERED buttonMask:NX_RESIZEBUTTONMASK|NX_MINIATURIZEBUTTONMASK defer:NO];
  128.     [theWindow setFreeWhenClosed:YES];
  129.     [theWindow setHideOnDeactivate:NO];
  130.     [theWindow setMiniwindowIcon:MINIWINDOWICON];
  131.     [theWindow setDelegate:self];
  132.     [theWindow moveTopLeftTo:(WINDOWRIGHTBOUND-frameRect->size.width) :(WINDOWTOPBOUND-((windowNum*WINDOWOFFSET)%WINDOWROLLBOUND))];
  133.     sprintf(buffer, GENERICTITLE, windowNum);
  134.     [theWindow setTitle:buffer];
  135.     [theWindow setContentView:scrollView];
  136.  
  137.     [theWindow display];
  138.     [NXApp addWindowsItem:theWindow title:buffer filename:NO];
  139.     [theWindow orderWindow:NX_BELOW relativeTo:[[NXApp mainWindow] windowNum]];
  140.     return self;
  141. }
  142.  
  143. - drawSelf:(NXRect *)r :(int)rectCount
  144. {
  145. DEBUG_FUNC1(DEBUGLEVEL);
  146.     [theImage composite:NX_COPY fromRect:r toPoint:&(r->origin)];
  147.     return self;
  148. }
  149.  
  150. - free
  151. {
  152. DEBUG_FUNC1(DEBUGLEVEL);
  153.     [theImage free];
  154.     [cache free];
  155.     return [super free];
  156. }
  157.  
  158. - setFlushMode:(unsigned)mode
  159. {
  160.     switch (mode)
  161.       {
  162.         case AUTOFLUSHMODE: flushTE = DPSAddTimedEntry(0.1, (DPSTimedEntryProc)flushTEHandler, self, NX_MODALRESPTHRESHOLD-1);
  163.                             flushMode = mode; break;
  164.     case NONFLUSHMODE: if (flushTE) DPSRemoveTimedEntry(flushTE);
  165.                        flushTE = (DPSTimedEntry)0; flushMode = mode;
  166.       }
  167.     return [self display];
  168. }
  169.  
  170. @end
  171.  
  172. @implementation GraphicsView (Delegate)
  173.  
  174. - windowWillResize:sender toSize:(NXSize *)aSize
  175. {
  176. DEBUG_FUNC1(DEBUGLEVEL);
  177.     if (aSize->width > maxWindowSize.width)
  178.       aSize->width = maxWindowSize.width;
  179.     if (aSize->width < minWindowSize.width)
  180.       aSize->width = minWindowSize.width;
  181.     if (aSize->height > maxWindowSize.height)
  182.       aSize->height = maxWindowSize.height;
  183.     if (aSize->height < minWindowSize.height)
  184.       aSize->height = minWindowSize.height;
  185.     return self;
  186. }   
  187.  
  188. @end
  189.  
  190. static void flushTEHandler(DPSTimedEntry te, double time, id self)
  191. {
  192.     [self display];
  193. }
  194.  
  195. @interface Window (FrameView)
  196. - _setCloseEnabled:(BOOL)aBoolean andDisplay:(BOOL)anotherBool;
  197. @end
  198.  
  199. @implementation Window (GraphicsExt)
  200.  
  201. - setCloseEnabled
  202. {
  203. DEBUG_FUNC1(DEBUGLEVEL);
  204.     [_borderView _setCloseEnabled:YES andDisplay:YES];
  205.     return self;
  206. }
  207.  
  208. @end
  209.